home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_05
/
allison
/
date5.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-12
|
776b
|
34 lines
LISTING 13 - Adds a stream inserter to the Date class
implementation
// date5.cpp
#include <iostream.h>
#include "date3.h"
const char * Date::month_text[13] =
{"Bad month", "January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December"};
Date::Date(int m, int d, int y) : month(m), day(d), year(y)
{}
ostream & operator<<(ostream & os, const Date &d)
{
os << Date::month_text[d.month]
<< ' ' << d.day
<< ", " << d.year;
return os;
}
int Date::compare(const Date & dp2) const
{
int result = year - dp2.year;
if (result == 0)
result = month - dp2.month;
if (result == 0)
result = day - dp2.day;
return result;
}